﻿using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
using ScrapySharp.Html;
using System;
using WxBean.Core.Model.Models.Python;

namespace WxBean.Core.Common.PythonCodeFile
{
    public class RunPython
    {
        public void RunPythonAsync()
        {
            ScriptRuntime pyRunTime = Python.CreateRuntime();
            //dynamic obj = pyRunTime.UseFile(@"C:\Users\Administrator\Desktop\项目\BCoreCore\WxBean.Core.Common\PythonCodeFile\m_top.py");

            dynamic obj = pyRunTime.UseFile(@"C:\Users\Administrator\Desktop\项目\BCoreCore\WxBean.Core.Common\PythonCodeFile\TestPythonFile.py");

            

            Console.WriteLine(obj.welcome("Test C# Call Python."));
            Console.WriteLine(obj.welcome("测试中文看看是否正常！"));
            
            DataObjectTest testObj = new DataObjectTest("张三", 20, "");

            Console.WriteLine("调用脚本前对象数据：{0}", testObj);
            obj.testAddAge(testObj);
            Console.WriteLine("调用 testAddAge 脚本后，对象数据={0}", testObj);
            obj.testAddAge2(testObj);
            Console.WriteLine("调用 testAddAge2 脚本后，对象数据={0}", testObj);


            // ==================================================
            // 测试 List.
            IronPython.Runtime.List testList = new IronPython.Runtime.List();
            testList.Add("List数据1");
            testList.Add("List数据2");
            testList.Add("List数据3");
            // 测试参数为 List.
            string result = obj.testList(testList);
            Console.WriteLine("调用 testList ， 返回结果：{0}", result);

            // ==================================================
            // 测试 Set.
            IronPython.Runtime.SetCollection testSet = new IronPython.Runtime.SetCollection();
            testSet.add("Set数据1");
            testSet.add("Set数据2");
            testSet.add("Set数据3");
            // 测试参数为 Set.
            result = obj.testSet(testSet);
            Console.WriteLine("调用 testSet ， 返回结果：{0}", result);

            // ==================================================
            // 测试 Dictionary.
            IronPython.Runtime.PythonDictionary testDictionary = new IronPython.Runtime.PythonDictionary();
            testDictionary["Key1"] = "Value1";
            testDictionary["Key2"] = "Value2";
            testDictionary["Key3"] = "Value3";
            // 测试参数为 Dictionary.
            result = obj.testDictionary(testDictionary);
            Console.WriteLine("调用 testDictionary ， 返回结果：{0}", result);
            Console.ReadLine();

        }
    }
}
